package com.example.demo.service.serviceimpl;

import com.example.demo.dao.FavoriteDao;
import com.example.demo.entity.FavoriteEntity;
import com.example.demo.service.FavoriteService;
import com.example.demo.vo.FavoriteVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FavoriteServiceImpl implements FavoriteService {
    @Resource
    FavoriteDao favoriteDao;

    @Override
    public List<FavoriteEntity> getUserFavorites(int user_id) {
        return favoriteDao.getFavoritesByUserId(user_id);
    }

    @Override
    public int addFavorite(FavoriteVo favoriteVo) {
        return favoriteDao.addFavorite(favoriteVo);
    }

    @Override
    public int deleteFavorite(int id) {
        return favoriteDao.delFavorite(id);
    }

    @Override
    public int deleteFavoriteByUserAndProduct(int user_id, int products_id) {
        return favoriteDao.delFavoriteByUserAndProduct(user_id, products_id);
    }

    @Override
    public boolean isFavoriteExists(int user_id, int products_id) {
        Integer count = favoriteDao.isFavoriteExists(user_id, products_id);
        return count != null && count > 0;
    }
}